class Sort{
     //选择排序
     selectSort(arr) {
        if (arr.length <= 1) return arr;
        for (let i = 0; i < arr.length; i++) {
            let minIndex = i;
            for (let j = i; j < arr.length; j++) {
                if (arr[minIndex] > arr[j]) {
                    minIndex = j;
                }
            }
            if (i != minIndex) {
                [arr[i], arr[minIndex]] = [arr[minIndex], arr[i]];
            }
        }
        return arr;
    }
    //冒泡排序
    bubbleSort(arr) {
        if (arr.length <= 1) return arr;
        for (let i = 0; i < arr.length; i++) {
            for (let j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
                }
            }
        }
        return arr;
    }
}

const sort = new Sort();
console.log(sort.bubbleSort([7,6,5,4,3,2,1]));
console.log(sort.selectSort([7,6,5,4,3,2,1]));
//排完序：[1,2,3,4,5,6,7]
